import { VersioningType, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as session from 'express-session';
import { NestExpressApplication } from '@nestjs/platform-express/interfaces';
import { join } from 'path';
// import { Response } from './common/response';
// import { HttpFilter } from './common/filter';

const whiteList = ['/list','/upload'];

function middleWareAll (req, res, next) {
    console.log(req.originalUrl, '全局中间件');
    if(whiteList.includes(req.originalUrl)){
        next();
    }else{
        res.send('无权限!');
    }
}

async function bootstrap() {
    const app = await NestFactory.create<NestExpressApplication>(AppModule);
    app.useStaticAssets(join(__dirname, 'images'),{
        prefix: "/img"
    });
    app.enableVersioning({
        type: VersioningType.URI
    });
    app.use(session({secret: "WangShan", name: "xm.session", rolling: true, cookie: { maxAge: null}}));
    // app.use(middleWareAll);
    // app.useGlobalInterceptors(new Response());
    // app.useGlobalFilters(new HttpFilter());
    app.useGlobalPipes(new ValidationPipe());
    await app.listen(3000);
}
bootstrap();
